<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <script>
        //1。窗口加载事件
        //加了window.onload js就可以放在任意位置
        window.onload = function() {
                var btn = document.querySelector("button");
                btn.addEventListener('click', function() {
                    alert("点击我了");
                })
            }
            //2.调整窗口大小事件
        window.addEventListener('load', function() {
            var div = document.querySelector('div');
            window.addEventListener('resize', function() {
                //window.innerWidth获取当前屏幕宽度
                console.log(window.innerWidth);
                console.log('窗口大小变化了');
                if (window.innerWidth < 800) {
                    div.style.display = 'none'
                } else {
                    div.style.display = 'block'
                }
            })
        })
    </script>
    <button>点击我</button>
    <div></div>
</body>

</html>